<!--点赞-->
<template>
  <div @click="up">
    <span class="icon-up icon-like" :class="{'icon-liked':hasUp}"></span>
    {{upsCount || 0}}
  </div>
</template>

<script>
  export default {
    name: '',
    props: ['commentId', 'contentId', 'upsCount','shareType','isUp'],
    components: {},
    data () {
      return {
        /*data: {
          ups: 0
        },*/
        hasUp: false,
      }
    },
    created () {
     this.loadData()
      // this.data.ups = this.upsCount
    },
    methods: {
      loadData () {
        /*let params = {
          contentId: this.contentId,
          commentId: this.commentId,
        }*/
        if(typeof this.shareType !='undefined' && this.shareType ===7){ //组工信息的评论点赞
          console.log('this.isUpthis.isUp',this.isUp);
          this.hasUp = this.isUp
          return
        }
        if(this.$store.state.isSpace){ //支部空间的评论点赞
          this.hasUp = this.isUp
          return
        }
        return this.fetchService.commentGetSfdz(this.commentId).then(res => {
          if (res.code !== 0) {
            return this.tools.tip(res.message || '接口服务出错，请联系管理员')
          }
          this.hasUp = res.data
          // this.data = res.data
          return res
        })
      },
      up () {
        if (this.hasUp === true) {
          return false
        }
        let params = {
          commentId: this.commentId,
          type: 1,
          contentId: this.contentId,
        }
        if(typeof this.shareType !='undefined' && this.shareType ===7){ //组工信息的评论点赞
          this.fetchService.groupInfoCommentInfoUps(params).then(res => {
            if (res.code !== 0) {
              return this.tools.tip(res.message || '接口服务出错，请联系管理员')
            }
            this.hasUp = true
            this.$emit("updateUpsAdd")
            return res
          })
          return
        }
        if(this.$store.state.isSpace){ //支部空间资料
          let data = {
            id: this.commentId,
          }
          this.fetchService.topic_opt_subSupport(data).then(res => {
            if (res.code !== 0) {
              return this.tools.tip(res.message || '接口服务出错，请联系管理员')
            }
            this.hasUp = true
            this.$emit("updateUpsAdd")
            return res
          })
          return
        }
        return this.fetchService.upsAndDowns(params).then(res => {
          if (res.code !== 0) {
            return this.tools.tip(res.message || '接口服务出错，请联系管理员')
          }
          this.hasUp = true
          this.$emit("updateUpsAdd")
          return res
        })
      }
    }
  }
</script>

<style scoped lang="scss">
  .title.link-arrow.link {
    border-color:#eeeeee;
    &.active {
      border-color:#0f9ceb;
    }
  }
</style>
